package com.sumansoul.mypaydemo;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.ViewTarget;
import com.bumptech.glide.request.transition.Transition;

import utils.GlideBlurTransformation;


public class MainActivity extends AppCompatActivity {


    private static final String TAG = "LUO";
    private String url1;
    private String url2;
    private  ImageView image1;
    private  ImageView image2;
    private  ImageView image3;
    private  RelativeLayout rl_background;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
         image1 = findViewById(R.id.image1);
         image2 = findViewById(R.id.image2);
         image3 = findViewById(R.id.image3);
         rl_background = findViewById(R.id.rl_background);

         url1 = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1587018016842&di=a45fd7e0a73fa060c831fd6d131b1d7d&imgtype=0&src=http%3A%2F%2Fpic26.nipic.com%2F20130122%2F5056611_171645641000_2.jpg";
         url2 = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1587018016841&di=b32e4e903272cbe825ae9e0104b78635&imgtype=0&src=http%3A%2F%2Fimg.taopic.com%2Fuploads%2Fallimg%2F130331%2F240460-130331064K470.jpg";

        initData();

    }

    private void initData() {

        /**
         * 图片1，普通图片
         */
        Glide.with(this).load(url1).into(image1);


        /**
         * 图片2，高斯模糊图片
         */
        Glide.with(this)
                .load(url2)
                .apply(RequestOptions.bitmapTransform(new GlideBlurTransformation(this)))
                .into(new ViewTarget<ImageView, Drawable>(image2) {
                    @Override
                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                        Drawable current = resource.getCurrent();
                        //image2.setBackground(current);
                        image2.setImageDrawable(current);
                    }
                });


        /**
         * 图片3，图片+高斯模糊背景（图片）
         */
        Glide.with(this).load(url2).into(image3);
        //图片3，图片+高斯模糊背景（背景）
        Glide.with(this)
                .load(url2)
                .apply(RequestOptions.bitmapTransform(new GlideBlurTransformation(this)))
                // .apply(RequestOptions.bitmapTransform( new BlurTransformation(context, 20)))
                .into(new ViewTarget<RelativeLayout, Drawable>(rl_background) {
                    @Override
                    public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                        Drawable current = resource.getCurrent();
                        rl_background.setBackground(current);
                    }
                });
    }


}
